-
Notifications
You must be signed in to change notification settings - Fork 125
TryteString.random() use cls.LEN as its default length, when available #167
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Radoslav. Thanks for jumping on this!!
I've requested a few changes, to make the code and error message a bit more explicit.
Also, could we include unit tests for this change?
iota/types.py
Outdated
@@ -60,6 +60,12 @@ def random(cls, length): | |||
alphabet = list(itervalues(AsciiTrytesCodec.alphabet)) | |||
generator = SystemRandom() | |||
|
|||
try: | |||
length = length or cls.LEN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would also trip if length == 0
; could we change this to an explicit is None
check?
iota/types.py
Outdated
length = length or cls.LEN | ||
except AttributeError: # class has no LEN attribute | ||
if length is None: | ||
raise TypeError("random() missing 1 required positional argument: 'length'") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like this might be confusing to some users, since the method signature shows length
as optional.
Maybe we could make this error explain that {class}
does not define a length property.
Hi @rpitonak let me know if there's anything I can do to help with this! |
Thanks @rpitonak ! I will take a look at this over the weekend. |
Cheers @rpitonak ! The changes look good. Two last things:
|
Change implemented in another PR, see #286 for details. |
Fix #166